package shuashuami.hb.com.avtivity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import shuashuami.hb.com.fragment.CUntreadtedTaskFragment;
import shuashuami.hb.com.fragment.CUntreadtedTaskZuofeiFragment;
import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.hdlibrary.util.fragment.ZoomOutPageTransformer;
import shuashuami.hb.com.view.PagerSlidingTabStrip;

public class CUntreatedTaskActivity extends AbActivity {
    private ViewPager contentPager;
    private mPagerAdapter adapter;
    private PagerSlidingTabStrip tabs;

    private EditText edit_next;

    private ImageView image_searchbtn;
    private boolean isSearch=false;

    private CUntreadtedTaskFragment cdistributionFragment1;
    private CUntreadtedTaskZuofeiFragment cdistributionFragment2;

    @Override
    protected void initUI() {
        setAbContentView(R.layout.activity_cuntreated_task);
        contentPager = (ViewPager) findViewById(R.id.content_pager_c_untreated_task);
        adapter = new mPagerAdapter(getSupportFragmentManager());
        contentPager.setAdapter(adapter);
        contentPager.setOffscreenPageLimit(2);
        contentPager.setPageTransformer(true, new ZoomOutPageTransformer());
        edit_next= (EditText) findViewById(R.id.edit_next);
        image_searchbtn= (ImageView) findViewById(R.id.image_searchbtn);

        tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs_c_untreated_task);
        tabs.setTextColorResource(R.color.gray);
        tabs.setDividerColorResource(R.color.view_unpressed);
        tabs.setIndicatorColorResource(R.color.blue);
        tabs.setSelectedTextColorResource(R.color.blue);
        tabs.setIndicatorHeight(4);
        tabs.setUnderlineHeight(2);
        tabs.setTextSize(12);
        tabs.setViewPager(contentPager);

    }

    @Override
    protected void initData() {
        setLeftView();

        cdistributionFragment1 = new CUntreadtedTaskFragment();
        cdistributionFragment1.setType("2");
        cdistributionFragment2 = new CUntreadtedTaskZuofeiFragment();
        cdistributionFragment2.setType("8");
    }

    @Override
    protected void initListener() {

        edit_next.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            //            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(!hasFocus){
                    edit_next.bringToFront();
                    isSearch=false;
                }else{
                    image_searchbtn.bringToFront();
                    isSearch=true;
                }

            }
        });

        image_searchbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isSearch){
                    edit_next.clearFocus();

                    cdistributionFragment1.disPlayData(edit_next.getText().toString());
                    cdistributionFragment2.disPlayData(edit_next.getText().toString());
                  //  cdistributionFragment4.disPlayData(edit_next.getText().toString());
                }
            }
        });

    }

    private class mPagerAdapter extends FragmentStatePagerAdapter {

        private String Title[] = {"待提交", "已作废"};

        public mPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int arg0) {
            // int[] id = { 5, 18, 27, 37, 21, 36, 23, 24 };
            if (arg0 == 0) {
                return cdistributionFragment1;
            } else {
                return cdistributionFragment2;
            }
        }

        @Override
        public int getCount() {
            return Title.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return Title[position];
        }

    }
}
